package model.connections;

import java.util.ArrayList;

import model.File;

public class Route {

	private ArrayList<Connection> connections;
	private File wantedFile;
	private int currentStep;
	private double evaluation;
	
	/**
	 * Data flow per iteration.
	 */
	private int dataFlow;
	
	private double stability;
	
	public Route(Connection connection, File wantedFile) {
		connections = new ArrayList<Connection>();
		addConnection(connection);
		setWantedFile(wantedFile);
		setCurrentStep(0);
	}
	
	public Route(ArrayList<Connection> connections, File wantedFile) {
		setConnections(connections);
		setWantedFile(wantedFile);
		setCurrentStep(0);
	}

	public ArrayList<Connection> getConnections() {
		return connections;
	}

	public void setConnections(ArrayList<Connection> connections) {
		this.connections = connections;
	}
	
	public void addConnection(Connection connection) {
		connections.add(connection);
	}

	public File getWantedFile() {
		return wantedFile;
	}

	public void setWantedFile(File wantedFile) {
		this.wantedFile = wantedFile;
	}

	public int getCurrentStep() {
		return currentStep;
	}

	public void setCurrentStep(int currentStep) {
		this.currentStep = currentStep;
	}

	public int getDataFlow() {
		return dataFlow;
	}

	public void setDataFlow(int dataFlow) {
		this.dataFlow = dataFlow;
	}
	
	public void stepForward() {
		if (getCurrentStep() >= getConnections().size()) {
			setCurrentStep(0);
			getWantedFile().setDownloadedSize(
					getWantedFile().getDownloadedSize() + getDataFlow()
					);
		} else {
			setCurrentStep(getCurrentStep() + 1);
		}
//		System.out.println("Data flow: "+getDataFlow());
//		System.out.println("current step: "+getCurrentStep()+" size: "+getConnections().size());
//		System.out.println("Downloaded file size "+getWantedFile().getDownloadedSize());
	}
	
	public Route clone() {
		ArrayList<Connection> list = new ArrayList<Connection>();
		for (Connection connection : connections) {
			list.add(connection.clone());
		}
		Route route = new Route(list, wantedFile);
		return route;
	}

	public double getEvaluation() {
		return evaluation;
	}

	public void setEvaluation(double evaluation) {
		this.evaluation = evaluation;
	}

	public double getStability() {
		return stability;
	}

	public void setStability(double stability) {
		this.stability = stability;
	}
}
